home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / gimp / 2.0 / plug-ins / palette-sort.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.1 KB  |  39 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from gimpfu import *
  5. gettext.install('gimp20-python', gimp.locale_directory, unicode = True)
  6.  
  7. def palette_sort(palette, model, channel, ascending):
  8.     editable = pdb.gimp_palette_is_editable(palette)
  9.     if not editable:
  10.         palette = pdb.gimp_palette_duplicate(palette)
  11.     
  12.     num_colors = pdb.gimp_palette_get_info(palette)
  13.     entry_list = []
  14.     for i in xrange(num_colors):
  15.         entry = (pdb.gimp_palette_entry_get_name(palette, i), pdb.gimp_palette_entry_get_color(palette, i))
  16.         index = entry[1][channel]
  17.         if model == 'HSV':
  18.             index = entry[1].to_hsv()[channel]
  19.         else:
  20.             index = entry[1][channel]
  21.         entry_list.append((index, entry))
  22.     
  23.     entry_list.sort((lambda x, y: cmp(x[0], y[0])))
  24.     if not ascending:
  25.         entry_list.reverse()
  26.     
  27.     for i in xrange(num_colors):
  28.         pdb.gimp_palette_entry_set_name(palette, i, entry_list[i][1][0])
  29.         pdb.gimp_palette_entry_set_color(palette, i, entry_list[i][1][1])
  30.     
  31.     return palette
  32.  
  33. register('python-fu-palette-sort', N_('Sort the colors in a palette'), 'palette_merge (palette, model, channel, ascending) -> new_palette', 'Joao S. O. Bueno Calligaris, Carol Spears', 'Joao S. O. Bueno Calligaris', '2006', N_('_Sort Palette...'), '', [
  34.     (PF_PALETTE, 'palette', _('Palette'), ''),
  35.     (PF_RADIO, 'model', _('Color _model'), 'HSV', ((_('RGB'), 'RGB'), (_('HSV'), 'HSV'))),
  36.     (PF_RADIO, 'channel', _('Channel to _sort'), 2, ((_('Red or Hue'), 0), (_('Green or Saturation'), 1), (_('Blue or Value'), 2))),
  37.     (PF_BOOL, 'ascending', _('_Ascending'), True)], [], palette_sort, menu = '<Palettes>', domain = ('gimp20-python', gimp.locale_directory))
  38. main()
  39.